/*******************************************************************************
 * Copyright (c) 2008 Sylvain Sicard.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Sylvain Sicard - initial API and implementation
 ******************************************************************************/
package fr.jade.examples.fraclite.orb.evalperf;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.factory.GenericFactory;
import org.objectweb.fractal.api.type.ComponentType;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.api.type.TypeFactory;
import org.objectweb.fractal.util.Fractal;

import fr.jade.examples.fraclite.orb.evalperf.Service;
import fr.jade.fraclite.orb.common.api.NamingService;
import fr.jade.fraclite.orb.common.ns.Registry;

/**
 * 
 * @author Sylvain Sicard
 *
 */
public class ClientLauncher {

	public static void main (final String[] args) throws Exception {
		NamingService ns = Registry.getRegistry();
		Component remoteBoot = ns.lookup("bootstrap");
		Component localBoot = Fractal.getBootstrapComponent();
		
		GenericFactory remotecf = Fractal.getGenericFactory(remoteBoot);
		GenericFactory localcf = Fractal.getGenericFactory(localBoot);
		TypeFactory tf = Fractal.getTypeFactory(localBoot);
		
		// type of server component
		ComponentType sType = tf.createFcType(new InterfaceType[] {
				tf.createFcItfType("s", "fr.jade.examples.fraclite.orb.evalperf.Service", false, false, false)});

	  // create server component
    Component sComp = remotecf.newFcInstance(sType, "primitive", "fr.jade.examples.fraclite.orb.evalperf.ServerImpl");

		Fractal.getNameController(sComp).setFcName("Server");
		
		Service s = (Service)sComp.getFcInterface("s");

		Argument o1 = new Argument();
    Argument o2 = new Argument();
    long begin, end;
    int nb = 10000;
    
// ===================================================================    
    System.out.println("Number of iterations: "+nb);
    System.out.println("Java");
    s.print1();
    begin = System.currentTimeMillis();
    for (int i=0 ; i <nb ; i++)
      s.print1();
    end = System.currentTimeMillis();
    System.out.println("void print() "+(end-begin));

    s.print2(o1);
    begin = System.currentTimeMillis();
    for (int i=0 ; i <nb ; i++)
      s.print2(o1);
    end = System.currentTimeMillis();
    System.out.println("void print(Object) "+(end-begin));

    s.print3(o1, o2);
    begin = System.currentTimeMillis();
    for (int i=0 ; i <nb ; i++)
      s.print3(o1, o2);
    end = System.currentTimeMillis();
    System.out.println("void print(Object, Object) "+(end-begin));

    s.print4(o1);
    begin = System.currentTimeMillis();
    for (int i=0 ; i <nb ; i++)
      s.print4(o1);
    end = System.currentTimeMillis();
    System.out.println("Object print(Object) "+(end-begin));
    
    s.print5(o1, o2);
    begin = System.currentTimeMillis();
    for (int i=0 ; i <nb ; i++)
      s.print5(o1, o2);
    end = System.currentTimeMillis();
    System.out.println("Object print(Object, Object) "+(end-begin));

	}
}
